-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Add reserved-memory support #35460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add reserved-memory support #35460
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No objections from me on the approach.
I know this is at RFC stage but I have random nitpicks and a couple of questions.
include/devicetree/reserved.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will require an update to doc/reference/devicetree/api.rst as well.
include/linker/devicetree_reserved.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tejlmand will need to review this to see how it's going to play with linker script generation, which is also a 2.7 feature.
@carlocaione my expectation is that you may need to lift this to cmake instead of .h at some point, based on what @tejlmand demonstrated at the TSC meeting today regarding toolchain abstractions and impact on linker scripts.
I'll let y'all sort out the details; I'm just calling attention to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not so worried on this.
It would of require that i'm able to do similar, but as we anyway need to obtain device tree info for the linker script generation I don't have concerns in this regard.
|
To quickly access the node using
Given that you could have this done using memory regions "far" from the used kernel space and accessing the memory using direct pointers in memory having sections is handy for several reasons:
The |
Lets remove it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates!
Yes. For now I'd like to keep it. |
Just pointing out that this is not strictly true. It will only fail at link time if variables placed in two memory regions overlay one another. You can test this easily by just duplicating the |
Thank you for the clarification. This is indeed what I see in my test where I usually create a buffer of the same size of the section to be used as memory pool. I can make that crated automatically, I'm open to any suggestion on how to improve this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @carlocaione
|
@galak ping |
dismissing @galak review because I addressed the comments long time ago already.
|
@carlescufi can we move this forward please? :) |
samples/boards/qemu_cortex_a53/reserved_memory/dts/bindings/sample_driver.yaml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this looks good, my only concern is adding DT_RESERVED_MEM_REGIONS / DT_RESERVED_MEM_SECTIONS to linker.ld unconditionally.
As its reasonable for someone to have reserved memory nodes w/o labels and this would somewhat break things.
So do we add a Kconfig option to enable the support.
One alternative is to generate the sections names from the node labels instead of the label property as in #36365. |
To be able to get a tokenize DT string without the quotes. Deprecate also DT_ENUM_TOKEN and DT_ENUM_UPPER_TOKEN. Signed-off-by: Carlo Caione <[email protected]>
Introduce a set of header files to be able to define and declare sections and regions in the linker script. Introduce also DT helpers to retrieve data back. Signed-off-by: Carlo Caione <[email protected]>
This won't be a problem anymore (and it will be reworked) once the @tejlmand work on the linker script generation will be merged. It's really not useful trying to fix this sort of things now when the whole system will be reworked soon.
As suggested by @JordanYates this can be fixed once his PR #36365 will be merged (and FWIW that approach looks sane to me).
Not clear what you are asking here, support for what? |
|
@galak @JordanYates added this to dev-review with the hope that we can settle it today. |
|
So I'd say either we have a customer linker script for the sample and drop the changes to the generic arm64 linker script or add a Kconfig option that wraps the changes in the linker script. I dont like the idea of adding something like this and knowing its going to change with @tejlmand changes. Lets either not add it right now or limit it to just the sample at this time. |
@galak changed to have a modified linker script only for the sample. |
Introduce sample application to test reserved-memory helpers. Signed-off-by: Carlo Caione <[email protected]>
This PR was inspired by #31077 (tagging @JordanYates)
What this RFC is about
This RFC is a potential answer to two different needs:
How this is solved on other OS
The Linux kernel is implementing the
reserved-memorynode for that, see the documentationHow this RFC is trying to solve this
The idea is having a light version of what Linux is doing. What I'm proposing here is formally introducing a
reserved-memorynode and a set of header files and macros doing the following:DT_RESERVED_REGIONS()macroDT_RESERVED_SECTIONS()macroDT_RESERVED_SYMBOLS()macroA couple of other
DT_RESERVED_*macros are also introduced to retrieve at run-time information about start and size of the reserved-memory region.Can you give me an example?
Sure. Let's say that we have this in the DT:
The
dma-buffer-managerdriver is managing the memory region0x42000000-0x42001000set with anon-cacheableattribute at boot time by MPU/MMU while thedriverdriver has access through the phandle to the memory region0x43000000-0x43001000. These drivers can use the macrosDT_RESERVED_GET_{SIZE,ADDR}andDT_RESERVED_GET{SIZE,ADDR}_BY_PHANDLEto access address and size of the appropriate memory region.In the linker script two more regions are created
res0andres1and two more sections.res0and.res1. Also new linker script symbols are being exportedreserved_res0_{start,end}andreserved_res1_{start,end}.How this solves the original problem
Having a real mechanism to actually reserve pages is a complex matter that usually involves MMU / MPU. What we are doing here is creating new sections and allow driver to make use of these new sections at very precise location in memory. If the sections are overlapping with other sections at compile time we get an error.
Also (very important) having access to the linker symbols, easily allows architectural code to set properties on the memory regions. For example MMU and MPU code can set proper attributes to the memory regions.
For example we can now pass
reserved_res0_startto a slab-allocator to be able to have easily slabs of non-cacheable memory.